package org.dtrd.modules.archive.entity.po;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.patient.entity.bean.PatientPublicAccountInfo;
import org.dtrd.modules.questionnaire.entity.bean.PatientBasicInfo;
import org.dtrd.modules.questionnaire.entity.bean.PatientDetailInfo;
import org.dtrd.modules.questionnaire.entity.bean.QuestionnaireRdVersionDetail;

import java.util.Date;


/**
 * <p>
 * 糖尿病概况
 * </p>
 *
 * @author xiao
 * @since 2022-07-08
 */
@Data
@TableName("dtrd_ent_rd_archive_overview")
public class DtrdEntRdArchiveOverview {

    @TableId(value = "data_id", type = IdType.AUTO)
    private Integer dataId;

    /**
     * 患者ID
     */
    @TableField("patient_id")
    private Integer patientId;

    /**
     * 记录时间
     */
    @TableField("record_date")
    private Date recordDate;

    /**
     * 是否确诊糖尿病
     */
    @TableField("if_diabetes")
    private Integer ifDiabetes;

    /**
     * 糖尿病类型：1-1型糖尿病,2-2型糖尿病,3-妊娠糖尿病,4-其他类型糖尿病,6-未诊断
     */
    @TableField("diabetes_type")
    private Integer diabetesType;

    /**
     * 确诊日期
     */
    @TableField("diabetes_diagnose_date")
    private Date diabetesDiagnoseDate;

    /**
     * 确诊情形  1-因有上述症状就医而确诊,2-因其他疾病就医而被发现,3-因健康体检而发现,4-因其他原因偶然发现
     */
    @TableField("diabetes_reason")
    private String diabetesReason;

    /**
     * 起病特点IDs，多个用半角逗号隔开
     */
    @TableField("diabetes_onset_symptom")
    private String diabetesOnsetSymptom;

    /**
     * 起病特点其他
     */
    @TableField("diabetes_onset_symptom_other")
    private String diabetesOnsetSymptomOther;

    /**
     * 体重变化
     */
    @TableField("weight_change")
    private Float weightChange;

    /**
     * 空腹血糖
     */
    @TableField("sugar_fasting")
    private Float sugarFasting;

    /**
     * 餐后血糖
     */
    @TableField("sugaf_after_eat")
    private Float sugafAfterEat;

    /**
     * 早餐前血糖
     */
    @TableField("sugar_breakfast_before")
    private Float sugarBreakfastBefore;

    /**
     * 早餐后血糖
     */
    @TableField("sugar_breakfast_after")
    private Float sugarBreakfastAfter;

    /**
     * 午餐前血糖
     */
    @TableField("sugar_lunch_before")
    private Float sugarLunchBefore;

    /**
     * 午餐后血糖
     */
    @TableField("sugar_lunch_after")
    private Float sugarLunchAfter;

    /**
     * 晚餐前血糖
     */
    @TableField("sugar_supper_before")
    private Float sugarSupperBefore;

    /**
     * 晚餐后血糖
     */
    @TableField("sugar_supper_after")
    private Float sugarSupperAfter;

    /**
     * 睡前血糖
     */
    @TableField("sugar_sleep_before")
    private Float sugarSleepBefore;

    /**
     * 夜间血糖
     */
    @TableField("sugar_sleep_after")
    private Float sugarSleepAfter;

    /**
     * 糖化血红蛋白
     */
    @TableField("hba1c")
    private Float hba1c;

    /**
     * 早发性心血管疾病家族史
     */
    @TableField("family_history_premature_angio")
    private Integer familyHistoryPrematureAngio;

    /**
     * 2型糖尿病家族史
     */
    @TableField("family_history_diabetes_2")
    private Integer familyHistoryDiabetes2;

    /**
     * 日血糖波动幅度
     */
    @TableField("sugar_wave")
    private Integer sugarWave;

    /**
     * 体重变化情况
     */
    @TableField("weight_state")
    private Integer weightState;

    /**
     * 0-未用药,1-口服药, 2-胰岛素 3-口服药+胰岛素
     */
    @TableField("drug_type")
    private Integer drugType;

    /**
     * 创建时间
     */
    @TableField("create_time")
    private Date createTime;

    @TableField("is_del")
    @TableLogic
    private Integer isDel;

    /**
     * 糖尿病概况是否确认完成, 1-是, 0-否
     */
    @TableField("is_finished")
    private Integer isFinished;

    /**
     * C肽
     */
    @TableField("c_peptide")
    private Float cPeptide;

    /**
     * C肽2h
     */
    @TableField("c_peptide2h")
    private Float cPeptide2h;

    /**
     * 餐后2小时血糖
     */
    @TableField("sugar_2h")
    private Float sugar2h;

    /**
     * 2小时胰岛素
     */
    @TableField("insulin_2h")
    private Float insulin2h;

    /**
     * 口服药类型   1-二甲双胍单药 2-两种以上口服降糖药 3-其他
     */
    @TableField("oral_type")
    private Integer oralType;

    /**
     * 用药描述
     */
    @TableField("drug_desc")
    private String drugDesc;

    /**
     * 过往治疗方案 1-生活方式干预 2-低碳饮食 3-药物治疗 4-其他
     */
    @TableField("history_treatment")
    private Integer historyTreatment;

    /**
     * 治疗意愿     1-减脂 2-胰岛素治疗 3-其他
     */
    @TableField("treatment_will")
    private Integer treatmentWill;

    /**
     * 发胖时段 1-幼年 2-成年 3-产后（女）
     */
    @TableField("fat_time")
    private Integer fatTime;

    /**
     * 肥胖年限
     */
    @TableField("fat_year")
    private Integer fatYear;

    /**
     * 肥胖类型 1-中心型（苹果型） 2-苹果型（梨型） 3-均匀型
     */
    @TableField("fat_type")
    private Integer fatType;

    /**
     * 临床问题 1-暂无 2-月经失调（女） 3-不孕（女） 2-阳痿（男） 3-不孕（男）
     */
    @TableField("clinical_issues")
    private Integer clinicalIssues;

    public DtrdEntRdArchiveOverview init() {
        createTime = new Date();
        isDel = 0;
        return this;
    }

    public DtrdEntRdArchiveOverview parseFromDTO(PatientPublicAccountInfo info) {
        // 糖尿病诊断
        String text = info.getPatientsDiabetisDiagnoseText();
        if (text.equals(Constant.DiagnoseStatus.UNDIAGNOSED.getName())) {
            ifDiabetes = Constant.DiagnoseStatus.UNDIAGNOSED.getType();
        } else {
            ifDiabetes = Constant.DiagnoseStatus.HAD_DIAGNOSED.getType();
        }
        diabetesType = info.getPatientsDiabetisType();
        diabetesDiagnoseDate = info.getPatientsConfirmedDate();
        // 糖化血红蛋白
        hba1c = info.getHba1c();
        // 血糖
        sugarFasting = info.getSugarLimosis();
        sugarBreakfastAfter = info.getSugarAfterBreakfast();
        sugarLunchBefore = info.getSugarBeforeLunch();
        sugarLunchAfter = info.getSugarAfterLunch();
        sugarSupperBefore = info.getSugarBeforeDinner();
        sugarSupperAfter = info.getSugarAfterDinner();
        sugarSleepBefore = info.getSugarBeforeSleep();
        sugarSleepAfter = info.getSugarEarlyDay();
        return this;
    }

    public DtrdEntRdArchiveOverview parseFromDTO(PatientBasicInfo dto) {
        ifDiabetes = dto.getDiabetesDiagnosis();
        diabetesType = dto.getDiabetesType();
        diabetesDiagnoseDate = dto.getDiabetesDiagnosisDate();
        return this;
    }

    public DtrdEntRdArchiveOverview parseFromDTO(PatientDetailInfo info) {
        patientId = info.getPatientId();
        hba1c = info.getHba1c();
        cPeptide = info.getCPeptide();
        cPeptide2h = info.getCPeptide2h();
        sugarFasting = info.getSugarFasting();
        sugar2h = info.getSugar2h();
        insulin2h = info.getInsulin2h();
        return this;
    }

    public DtrdEntRdArchiveOverview parseFromDTO(QuestionnaireRdVersionDetail dto) {
        patientId = dto.getPatientId();
        ifDiabetes = dto.getDiabetesDiagnosis();
        diabetesType = dto.getDiabetesType();
        diabetesDiagnoseDate = dto.getDiabetesDiagnosisDate();
        cPeptide = dto.getCPeptide();
        cPeptide2h = dto.getCPeptide2h();
        sugarFasting = dto.getSugarFasting();
        sugar2h = dto.getSugar2h();
        insulin2h = dto.getInsulin2h();
        return this;
    }

}
